package com.zbkj.crmeb.merchant.admin.controller;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.constants.Constants;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.system.model.SystemGroupData;
import com.zbkj.crmeb.system.request.SystemGroupDataSearchRequest;
import com.zbkj.crmeb.system.service.SystemGroupDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/admin/mer/system/group/data")
@Api(tags = "商户热门搜索词")
public class MerSystemGroupDataController extends AdminBaseController{

    @Autowired
    private SystemGroupDataService systemGroupDataService;

    @GetMapping("/list")
    @ApiOperation(value = "热门搜索列表")
    public CommonResult<CommonPage<SystemGroupData>> getList(SystemGroupDataSearchRequest request, PageParamRequest pageParamRequest, HttpServletRequest servletRequest) {
        request.setMerId(getMerId(servletRequest));
        request.setGid(Constants.GROUP_DATA_ID_INDEX_KEYWORDS);
        return CommonResult.success(CommonPage.restPage(systemGroupDataService.getList(request, pageParamRequest)));
    }

    @PutMapping("/{id}/{status}")
    @ApiOperation(value = "更新热门搜索词是否在小程序显示")
    public CommonResult<Boolean> updateStatus(@PathVariable Integer id, @PathVariable Boolean status) {
        return CommonResult.success(systemGroupDataService.updateStatus(id, status));
    }
}
